package com.atfcm.stack;

import java.util.Deque;
import java.util.LinkedList;

public class T_739_每日温度 {
    public int[] dailyTemperatures(int[] temperatures) {
        int[] res = new int[temperatures.length];

        // 递减
        Deque<Integer> stack = new LinkedList<>();

        for(int i = 0; i < temperatures.length; i++){
            res[i] = 0;
            while (!stack.isEmpty() &&temperatures[stack.peek()] < temperatures[i]){
                Integer pop = stack.pop();
                res[pop] = i - pop;
            }
            stack.push(i);
        }
        return res;

    }
}
